home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / VLA_FONT.ZIP / MODEX.INC < prev    next >
Text File  |  1993-09-26  |  21KB  |  725 lines

  1. LABEL X320Y200 word 
  2.     db      00      ; 0e3h    ; dot clock
  3.     db      02      ; Number of CRTC Registers to update
  4.     dw      00014h  ; turn off dword mode
  5.     dw      0e317h  ; turn on byte mode
  6.     dw      320     ; width
  7.     dw      200     ; height
  8.  
  9. LABEL X320Y200s word 
  10.     db      0e3h    ; dot clock
  11.     db      02      ; Number of CRTC Registers to update
  12.     dw      00014h  ; turn off dword mode
  13.     dw      0e317h  ; turn on byte mode
  14.     dw      320     ; width
  15.     dw      200     ; height
  16.  
  17. LABEL X320Y240 word
  18.     db      0e3h    ; dot clock
  19.     db      10      ; Number of CRTC Registers to update
  20.     dw      00d06h  ; vertical total
  21.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  22.     dw      04109h  ; cell height (2 to double-scan)
  23.     dw      0ea10h  ; v sync start
  24.     dw      0ac11h  ; v sync end and protect cr0-cr7
  25.     dw      0df12h  ; vertical displayed
  26.     dw      00014h  ; turn off dword mode
  27.     dw      0e715h  ; v blank start
  28.     dw      00616h  ; v blank end
  29.     dw      0e317h  ; turn on byte mode
  30.     dw      320     ; width
  31.     dw      240     ; height
  32.  
  33. LABEL X360Y200 word
  34.     db      0e7h    ; dot clock
  35.     db      08      ; Number of CRTC Registers to update
  36.     dw      06b00h  ; horz total
  37.     dw      05901h  ; horz displayed
  38.     dw      05a02h  ; start horz blanking
  39.     dw      08e03h  ; end horz blanking
  40.     dw      05e04h  ; start h sync
  41.     dw      08a05h  ; end h sync
  42.     dw      00014h  ; turn off dword mode
  43.     dw      0e317h  ; turn on byte mode
  44.     dw      360     ; width
  45.     dw      200     ; height
  46.  
  47. LABEL X360Y240 word
  48.     db      0e7h    ; dot clock
  49.     db      16      ; Number of CRTC Registers to update
  50.     dw      06b00h  ; horz total
  51.     dw      05901h  ; horz displayed
  52.     dw      05a02h  ; start horz blanking
  53.     dw      08e03h  ; end horz blanking
  54.     dw      05e04h  ; start h sync
  55.     dw      08a05h  ; end h sync
  56.     dw      00d06h  ; vertical total
  57.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  58.     dw      04109h  ; cell height (2 to double-scan)
  59.     dw      0ea10h  ; v sync start
  60.     dw      0ac11h  ; v sync end and protect cr0-cr7
  61.     dw      0df12h  ; vertical displayed
  62.     dw      00014h  ; turn off dword mode
  63.     dw      0e715h  ; v blank start
  64.     dw      00616h  ; v blank end
  65.     dw      0e317h  ; turn on byte mode
  66.     dw      360
  67.     dw      240
  68.  
  69. LABEL X376Y282 word
  70.     db      0e7h
  71.     db      18
  72.     dw      06e00h  ; horz total
  73.     dw      05d01h  ; horz displayed
  74.     dw      05e02h  ; start horz blanking
  75.     dw      09103h  ; end horz blanking
  76.     dw      06204h  ; start h sync
  77.     dw      08f05h  ; end h sync
  78.     dw      06206h  ; vertical total
  79.     dw      0f007h  ; overflow
  80.     dw      06109h  ; cell height
  81.     dw      0310fh  ;
  82.     dw      03710h  ; v sync start
  83.     dw      08911h  ; v sync end and protect cr0-cr7
  84.     dw      03312h  ; vertical displayed
  85.     dw      02f13h  ; offset
  86.     dw      00014h  ; turn off dword mode
  87.     dw      03c15h  ; v blank start
  88.     dw      05c16h  ; v blank end
  89.     dw      0e317h  ; turn on byte mode
  90.     dw      376
  91.     dw      564
  92.  
  93. LABEL X320Y400 word
  94.     db      00      ;0e3h    ; dot clock
  95.     db      03      ; Number of CRTC Registers to update
  96.     dw      04009h  ; cell height
  97.     dw      00014h  ; turn off dword mode
  98.     dw      0e317h  ; turn on byte mode
  99.     dw      320     ; width
  100.     dw      400     ; height
  101.  
  102. LABEL X320Y480 word
  103.     db      0e3h    ; dotclock
  104.     db      10      ; Number of CRTC Registers to update
  105.     dw      00d06h  ; vertical total
  106.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  107.     dw      04009h  ; cell height (2 to double-scan)
  108.     dw      0ea10h  ; v sync start
  109.     dw      0ac11h  ; v sync end and protect cr0-cr7
  110.     dw      0df12h  ; vertical displayed
  111.     dw      00014h  ; turn off dword mode
  112.     dw      0e715h  ; v blank start
  113.     dw      00616h  ; v blank end
  114.     dw      0e317h  ; turn on byte mode
  115.     dw      320     ; width
  116.     dw      480     ; height
  117.  
  118. LABEL X360Y400 word
  119.     db      0e7h    ; dot clock
  120.     db      09      ; Number of CRTC Registers to update
  121.     dw      06b00h  ; horz total
  122.     dw      05901h  ; horz displayed
  123.     dw      05a02h  ; start horz blanking
  124.     dw      08e03h  ; end horz blanking
  125.     dw      05e04h  ; start h sync
  126.     dw      08a05h  ; end h sync
  127.     dw      04009h  ; cell height
  128.     dw      00014h  ; turn off dword mode
  129.     dw      0e317h  ; turn on byte mode
  130.     dw      360     ; width
  131.     dw      400     ; height
  132.  
  133.  
  134. LABEL X360Y480 word
  135.     db      0e7h
  136.     db      17
  137.     dw      06b00h  ; horz total
  138.     dw      05901h  ; horz displayed
  139.     dw      05a02h  ; start horz blanking
  140.     dw      08e03h  ; end horz blanking
  141.     dw      05e04h  ; start h sync
  142.     dw      08a05h  ; end h sync
  143.     dw      00d06h  ; vertical total
  144.     dw      03e07h  ; overflow
  145.     dw      04009h  ; cell height
  146.     dw      0ea10h  ; v sync start
  147.     dw      0ac11h  ; v sync end and protect cr0-cr7
  148.     dw      0df12h  ; vertical displayed
  149.     dw      02d13h  ; offset
  150.     dw      00014h  ; turn off dword mode
  151.     dw      0e715h  ; v blank start
  152.     dw      00616h  ; v blank end
  153.     dw      0e317h  ; turn on byte mode
  154.     dw      360
  155.     dw      480
  156.  
  157. LABEL X360Y360 word
  158.     db      0e7h
  159.     db      15
  160.     dw      06b00h  ; horz total
  161.     dw      05901h  ; horz displayed
  162.     dw      05a02h  ; start horz blanking
  163.     dw      08e03h  ; end horz blanking
  164.     dw      05e04h  ; start h sync
  165.     dw      08a05h  ; end h sync
  166.     dw      04009h  ; cell height
  167.     dw      08810h  ; v sync start
  168.     dw      08511h  ; v sync end and protect cr0-cr7
  169.     dw      06712h  ; vertical displayed
  170.     dw      02d13h  ; offset
  171.     dw      00014h  ; turn off dword mode
  172.     dw      06d15h  ; v blank start
  173.     dw      0ba16h  ; v blank end
  174.     dw      0e317h  ; turn on byte mode
  175.     dw      360
  176.     dw      360
  177.  
  178. LABEL X376Y308 word
  179.     db      0e7h
  180.     db      18
  181.     dw      06e00h  ; horz total
  182.     dw      05d01h  ; horz displayed
  183.     dw      05e02h  ; start horz blanking
  184.     dw      09103h  ; end horz blanking
  185.     dw      06204h  ; start h sync
  186.     dw      08f05h  ; end h sync
  187.     dw      06206h  ; vertical total
  188.     dw      00f07h  ; overflow
  189.     dw      04009h  ;
  190.     dw      0310fh  ;
  191.     dw      03710h  ; v sync start
  192.     dw      08911h  ; v sync end and protect cr0-cr7
  193.     dw      03312h  ; vertical displayed
  194.     dw      02f13h  ; offset
  195.     dw      00014h  ; turn off dword mode
  196.     dw      03c15h  ; v blank start
  197.     dw      05c16h  ; v blank end
  198.     dw      0e317h  ; turn on byte mode
  199.     dw      376
  200.     dw      308
  201.  
  202. LABEL X376Y564 word
  203.     db      0e7h
  204.     db      18
  205.     dw      06e00h  ; horz total
  206.     dw      05d01h  ; horz displayed
  207.     dw      05e02h  ; start horz blanking
  208.     dw      09103h  ; end horz blanking
  209.     dw      06204h  ; start h sync
  210.     dw      08f05h  ; end h sync
  211.     dw      06206h  ; vertical total
  212.     dw      0f007h  ; overflow
  213.     dw      06009h  ;
  214.     dw      0310fh  ;
  215.     dw      03710h  ; v sync start
  216.     dw      08911h  ; v sync end and protect cr0-cr7
  217.     dw      03312h  ; vertical displayed
  218.     dw      02f13h  ; offset
  219.     dw      00014h  ; turn off dword mode
  220.     dw      03c15h  ; v blank start
  221.     dw      05c16h  ; v blank end
  222.     dw      0e317h  ; turn on byte mode
  223.     dw      376
  224.     dw      564
  225.  
  226. LABEL X256Y240 word
  227.     db      0e3h    ; dot clock
  228.     db      16      ; Number of CRTC Registers to update
  229.  
  230.     dw      05f00h  ; horz total
  231.     dw      03f01h  ; horz displayed
  232.     dw      04002h  ;04202h  ; start horz blanking
  233.     dw      0a003h  ;09f03h  ; end horz blanking
  234.     dw      04f04h  ; start h sync
  235.     dw      00405h  ; end h sync
  236.  
  237.     dw      00d06h  ; vertical total
  238.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  239.     dw      04109h  ; cell height (2 to double-scan)
  240.     dw      0ea10h  ; v sync start
  241.     dw      0ac11h  ; v sync end and protect cr0-cr7
  242.     dw      0df12h  ; vertical displayed
  243.     dw      0e715h  ; v blank start
  244.     dw      00616h  ; v blank end
  245.  
  246.     dw      00014h  ; turn off dword mode
  247.     dw      0e317h  ; turn on byte mode
  248.     dw      256
  249.     dw      240
  250.  
  251. LABEL X256Y70 word
  252.     db      0e3h    ; dot clock
  253.     db      16      ; Number of CRTC Registers to update
  254.  
  255.     dw      05f00h  ; horz total
  256.     dw      03f01h  ; horz displayed
  257.     dw      04002h  ;04202h  ; start horz blanking
  258.     dw      0a003h  ;09f03h  ; end horz blanking
  259.     dw      04f04h  ; start h sync
  260.     dw      00405h  ; end h sync
  261.  
  262.     dw      00d06h  ; vertical total
  263.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  264.     dw      04709h  ; cell height (8 to get blocky)
  265.     dw      0ea10h  ; v sync start
  266.     dw      0ac11h  ; v sync end and protect cr0-cr7
  267.     dw      0df12h  ; vertical displayed
  268.     dw      0e715h  ; v blank start
  269.     dw      00616h  ; v blank end
  270.  
  271.     dw      00014h  ; turn off dword mode
  272.     dw      0e317h  ; turn on byte mode
  273.     dw      256
  274.     dw      240
  275.  
  276. LABEL X256Y154 word
  277.     db      0e3h    ; dot clock
  278.     db      18      ; Number of CRTC Registers to update
  279.  
  280.     dw      05f00h  ; horz total
  281.     dw      03f01h  ; horz displayed
  282.     dw      04002h  ;04202h  ; start horz blanking
  283.     dw      0a003h  ;09f03h  ; end horz blanking
  284.     dw      04f04h  ; start h sync
  285.     dw      00405h  ; end h sync
  286.  
  287.     dw      06206h  ; vertical total
  288.     dw      00f07h  ; overflow
  289.     dw      04109h  ; CELL HEIGHT
  290.     dw      0310fh  ;
  291.     dw      03710h  ; v sync start
  292.     dw      08911h  ; v sync end and protect cr0-cr7
  293.     dw      03312h  ; vertical displayed
  294.     dw      02f13h  ; offset
  295.     dw      00014h  ; turn off dword mode
  296.     dw      03c15h  ; v blank start
  297.     dw      05c16h  ; v blank end
  298.     dw      0e317h  ; turn on byte mode
  299.     dw      256
  300.     dw      308
  301.  
  302. LABEL X256Y282 word
  303.     db      0e3h    ; dot clock
  304.     db      18      ; Number of CRTC Registers to update
  305.  
  306.     dw      05f00h  ; horz total
  307.     dw      03f01h  ; horz displayed
  308.     dw      04002h  ;04202h  ; start horz blanking
  309.     dw      0a003h  ;09f03h  ; end horz blanking
  310.     dw      04f04h  ; start h sync
  311.     dw      00405h  ; end h sync
  312.  
  313.     dw      06206h  ; vertical total
  314.     dw      0f007h  ; overflow
  315.     dw      06109h  ; cell height
  316.     dw      0310fh  ;
  317.     dw      03710h  ; v sync start
  318.     dw      08911h  ; v sync end and protect cr0-cr7
  319.     dw      03312h  ; vertical displayed
  320.     dw      02f13h  ; offset
  321.     dw      00014h  ; turn off dword mode
  322.     dw      03c15h  ; v blank start
  323.     dw      05c16h  ; v blank end
  324.     dw      0e317h  ; turn on byte mode
  325.     dw      256
  326.     dw      564
  327.  
  328.     
  329. LABEL X256Y200 word
  330.     db      0e3h    ; dot clock
  331.     db      8       ; Number of CRTC Registers to update
  332.     dw      05f00h  ; horz total
  333.     dw      03f01h  ; horz displayed
  334.     dw      04002h  ; start horz blanking
  335.     dw      0a003h  ; end horz blanking
  336.     dw      04f04h  ; start h sync
  337.     dw      00405h  ; end h sync
  338.     dw      00014h  ; turn off dword mode
  339.     dw      0e317h  ; turn on byte mode
  340.     dw      256
  341.     dw      200
  342.  
  343. LAST_X_MODE        =     17
  344.  
  345. LABEL ModeTable word    ; Mode X tweak table
  346.     dw      offset X320Y200
  347.     dw      offset X320Y240
  348.     dw      offset X360Y200
  349.     dw      offset X360Y240
  350.     dw      offset X376Y282
  351.     dw      offset X320Y400
  352.     dw      offset X320Y480
  353.     dw      offset X360Y400
  354.     dw      offset X360Y480
  355.     dw      offset X360Y360
  356.     dw      offset X376Y308
  357.     dw      offset X376Y564
  358.     dw      offset X256Y240
  359.     dw      offset x256y200
  360.     dw      offset X320Y200s
  361.     dw      offset x256y154
  362.     dw      offset x256y282
  363.     dw      offset x256y70
  364.     
  365. M320x200x256 =0     ;constants for easy calling
  366. M320x240x256 =1
  367. M360x200x256 =2
  368. M360x240x256 =3
  369. M376x282x256 =4
  370. M320x400x256 =5
  371. M320x480x256 =6
  372. M360x400x256 =7
  373. M360x480x256 =8
  374. M360x360x256 =9
  375. M376x308x256 =10
  376. M376x564x256 =11
  377. M256x240x256 =12    ;GREAT modes - ypos is upper byte, xpos is lower
  378. M256x200x256 =13
  379. M320x200x256s=14
  380. M256x154x256 =15
  381. M256x282x256 =16
  382. M256x70x256 =17
  383.  
  384. InputStatus1=   3dah
  385. MISC_OUTPUT =   3c2h
  386. SC_Index    =   3c4h
  387. CRTC_Index  =   3d4h
  388. Graph_Index =   3ceh
  389. Attr_Index  =   3c0h    ;don't forget to clear flipflop & set bit 5 on index
  390. PEL_Write   =   3c8h
  391. PEL_Read    =   3c7h
  392. PEL_Data    =   3c9h
  393.  
  394. VGASeg      dw  0a000h
  395. ModeXWidth  dw  0
  396. ModeXHeight dw  0
  397. ModeXLogWidth dw 0
  398.  
  399. ;-----------------------------------------------------------------------
  400. ;
  401. ;   Sets mode # in AX, returns ax=0 if successful, ax=-1 if failed
  402. ;   cx= width of screen 
  403. ;
  404. ; SetModeX Adapted for VLA by Draeden,
  405. ; Originally written by Themie Gouthas,
  406. ; who adapted parts from M. Abrash code.
  407. ; (Talk about code reuse!)
  408. ;------------------------------------------------------------------------
  409. _Mode   dw  0
  410. _Scrw   dw  0
  411.  
  412. MACRO @SetModeX DaMode,DaWidth
  413.     mov     ax,DaMode
  414.     mov     cx,DaWidth
  415.     call    _Set_X_Mode
  416. ENDM @SetModeX
  417.  
  418. PROC _Set_X_Mode NEAR
  419.     pusha
  420.     push    es ds
  421.  
  422.     cld
  423.     mov     bx,cs
  424.     mov     ds,bx
  425.     mov     es,bx
  426.  
  427.     cmp     ax,LAST_X_MODE      ; have we selected a valid mode?
  428.     jle     @@ValidMode         ; Yes !
  429.  
  430.     pop     ds es
  431.     popa
  432.     mov     ax,-1               ; idiot.
  433.     ret
  434.  
  435. @@ValidMode:
  436.     mov     [_Mode],ax
  437.     mov     [_Scrw],cx
  438.  
  439.     mov     ax,13h              ; let the BIOS set standard 256-color
  440.     int     10h                 ;  mode (320x200 linear)
  441.     
  442.     mov     dx,SC_INDEX
  443.     mov     ax,0604h
  444.     out     dx,ax               ; disable chain4 mode
  445.     mov     ax,0100h
  446.     out     dx,ax               ; synchronous reset while setting Misc
  447.                                 ;  Output for safety, even though clock
  448.                                 ;  unchanged
  449.     mov     bx,[_Mode]
  450.     add     bx,bx
  451.     mov     si,[bx + ModeTable]
  452.     lodsb
  453.  
  454.     or      al,al
  455.     jz      @@DontSetDot
  456.     mov     dx,MISC_OUTPUT
  457.     out     dx,al               ; select the dot clock and Horiz
  458.                                 ;  scanning rate
  459. @@DontSetDot:
  460.     mov     dx,SC_INDEX
  461.     mov     ax,0300h
  462.     out     dx,ax               ; undo reset (restart sequencer)
  463.  
  464.     mov     dx,CRTC_INDEX       ; reprogram the CRT Controller
  465.     mov     al,11h              ; VSync End reg contains register write
  466.     out     dx,al               ; protect bit
  467.     inc     dx                  ; CRT Controller Data register
  468.     in      al,dx               ; get current VSync End register setting
  469.     and     al,07fh             ; remove write protect on various
  470.     out     dx,al               ; CRTC registers
  471.     dec     dx                  ; CRT Controller Index
  472.     cld
  473.     xor     cx,cx
  474.     lodsb
  475.     mov     cl,al
  476.  
  477. @@SetCRTParmsLoop:
  478.     lodsw                       ; get the next CRT Index/Data pair
  479.     out     dx,ax               ; set the next CRT Index/Data pair
  480.     dec     cx
  481.     jne     @@SetCRTParmsLoop
  482.  
  483.     lodsw
  484.     mov     [cs:ModeXWidth],ax
  485.     lodsw
  486.     mov     [cs:ModeXHeight],ax
  487.  
  488.     mov     dx,SC_INDEX
  489.     mov     ax,0f02h
  490.     out     dx,ax               ; enable writes to all four planes
  491.  
  492.                                 ; now clear all display memory, 8 pixels
  493.     mov     es,[cs:VGAseg]      ; at a time
  494.     sub     di,di               ; point ES:DI to display memory
  495.     sub     ax,ax               ; clear to zero-value pixels
  496.     mov     cx,8000h            ; # of words in display memory
  497.     rep     stosw               ; clear all of display memory
  498.     
  499.     ;  Mode X is set, now set the required logical page width.
  500.  
  501.     mov     cx,[cs:_Scrw]
  502.     shr     cx,2
  503.     mov     [cs:ModeXLogWidth],cx
  504.     shr     cx,1            ;divide by 8
  505.     mov     dx,CRTC_INDEX
  506.     mov     al,13h
  507.     mov     ah,cl
  508.     out     dx,ax
  509.  
  510.     pop     ds es
  511.     popa
  512.     xor     ax,ax
  513.     ret
  514. ENDP _Set_X_Mode
  515.  
  516. ────────────────────────────────────────────────────────────────────────────
  517. ;*   MISC planar mode routines
  518. ────────────────────────────────────────────────────────────────────────────
  519.  
  520.     ;ah: 0000b : bit 0= plane 0, bit 1=plane 1, etc..
  521.     ;
  522.     ;DESTROYS: al, dx
  523.     ;
  524. MACRO  @Set_Write_Plane
  525.     mov     dx,SC_Index
  526.     mov     al,2
  527.     and     ah,1111b
  528.     out     dx,ax
  529. ENDM   @Set_Write_Plane
  530.  
  531.     ;ah: plane to latch for read (0-3)
  532.     ;
  533.     ;DESTROYS: al, dx
  534.     ;
  535. MACRO  @Set_Read_Plane
  536.     mov     dx,Graph_Index
  537.     mov     al,4
  538.     out     dx,ax
  539. ENDM   @Set_Read_Plane
  540.  
  541.     ;ah: write mode (0-3)
  542.     ;
  543.     ;DESTROYS: ax, dx
  544.     ;
  545. MACRO @Set_Write_Mode
  546.     mov     dx,Graph_Index
  547.     mov     al,5
  548.     out     dx,al
  549.     inc     dx
  550.     in      al,dx
  551.     and     al,11111100b    ;clear out write mode bits
  552.     and     ah,00000011b
  553.     or      al,ah
  554.     out     dx,al
  555. ENDM  @Set_Write_Mode
  556.  
  557.     ;ah: Read mode (0-1)
  558.     ;
  559.     ;DESTROYS: ax, dx
  560.     ;
  561. MACRO @Set_Read_Mode
  562.     mov     dx,Graph_Index
  563.     mov     al,5
  564.     out     dx,al
  565.     inc     dx
  566.     in      al,dx
  567.     and     al,11110111b    ;clear out write mode bits
  568.     shl     ah,3            ;move bit to correct position
  569.     and     ah,00001000b
  570.     or      al,ah
  571.     out     dx,al
  572. ENDM  @Set_Read_Mode
  573.  
  574.     ;bx: starting offset
  575.     ;
  576.     ;DESTROYS: ax, dx
  577.     ;
  578. MACRO @Set_Start_Offset
  579.     mov     dx,CRTC_Index
  580.     mov     al,0ch
  581.     mov     ah,bh       ;write the HIGH byte
  582.     out     dx,ax
  583.     inc     al
  584.     mov     ah,bl       ;write the LOW byte
  585.     out     dx,ax
  586. ENDM  @Set_Start_Offset
  587.  
  588.     ;ah = pelpan value
  589.     ;
  590.     ;DESTROYS: ax, dx
  591.     ;
  592. MACRO @Set_HPP
  593.     mov     dx,InputStatus1
  594.     in      al,dx           ;dummy input
  595.     mov     dx,Attr_Index
  596.     mov     al,33h
  597.     out     dx,al
  598.     mov     al,ah
  599.     out     dx,al
  600. ENDM
  601.     
  602.     ;DESTROYS: ax, dx   - sets pixel pan compatibility
  603.     ;
  604. MACRO @Set_PPC
  605.     mov     dx,InputStatus1
  606.     in      al,dx           ;dummy input
  607.     mov     dx,Attr_Index
  608.     mov     al,30h
  609.     out     dx,al
  610.     inc     dx
  611.     in      al,dx
  612.     dec     dx
  613.     or      al,00100000b
  614.     out     dx,al
  615. ENDM
  616.  
  617.     ;bx: scanline to set split screen at
  618.     ;
  619.     ;DESTROYS: ax, dx
  620.     ;
  621. MACRO @Set_Split
  622.     mov     al,18h
  623.     mov     ah,bl
  624.     mov     dx,CRTC_Index
  625.     out     dx,ax       ;set bits 0-7
  626.  
  627.     mov     al,09h
  628.     out     dx,al
  629.     inc     dx
  630.     in      al,dx
  631.     mov     ah,bh
  632.     and     ah,00000010b
  633.     shl     ah,5
  634.     and     al,10111111b
  635.     or      al,ah
  636.     out     dx,al       ;set bit 9
  637.  
  638.     dec     dx
  639.     mov     al,07h
  640.     out     dx,al
  641.     inc     dx
  642.     in      al,dx
  643.     and     al,11101111b
  644.     mov     ah,bh
  645.     and     ah,00000001b
  646.     shl     ah,4
  647.     or      al,ah
  648.     out     dx,al       ;set bit 8
  649. ENDM @Set_SPlit
  650.  
  651. MACRO @FullVertWait
  652.  LOCAL @@Vr, @@Nvr
  653.     mov     dx,InputStatus1
  654. @@Vr:
  655.     in      al,dx
  656.     test    al,8
  657.     jz      @@Vr                    ;wait until Verticle Retrace starts
  658. @@Nvr:
  659.     in      al,dx
  660.     test    al,8
  661.     jnz     @@Nvr                   ;wait until Verticle Retrace Ends
  662. ENDM @FullVertWait
  663.  
  664. MACRO @WaitVert
  665.  LOCAL @@Vr
  666.     mov     dx,InputStatus1
  667. @@VR:
  668.     in      al,dx
  669.     test    al,8
  670.     jz      @@VR                    ;wait until Verticle Retrace starts
  671. ENDM  @WaitVert
  672.  
  673. MACRO @WaitVertEnd
  674.   LOCAL @@NVr
  675.     mov     dx,InputStatus1
  676. @@NVR:
  677.     in      al,dx
  678.     test    al,8
  679.     jnz     @@NVR                   ;wait until Verticle Retrace Ends
  680. ENDM  @WaitVertEnd
  681.     
  682.     ;si = offset to palette
  683.     ;cx = number of colors to write
  684.     ;al = starting palette register
  685.     ;
  686.     ;DESTROYS: dx,si,cx
  687.     ;
  688. MACRO @WritePalette
  689.     mov     dx,cx
  690.     add     cx,cx
  691.     add     cx,dx
  692.     mov     dx,03c8h
  693.     out     dx,al
  694.     inc     dx
  695.     cld
  696.     rep outsb
  697. ENDM @WritePalette
  698.  
  699.     ;Changes the mode back to ModeX after a ResetLinear was called
  700. MACRO @ResetModeX
  701.     mov     dx,SC_INDEX
  702.     mov     ax,0604h
  703.     out     dx,ax               ; disable chain4 mode
  704.     
  705.     mov     dx,CRTC_INDEX
  706.     mov     ax,00014h           ; turn off dword mode
  707.     out     dx,ax
  708.     mov     ax,0e317h           ; turn on byte mode
  709.     out     dx,ax
  710. ENDM
  711.  
  712.     ;changes from ModeX to normal linear mode
  713.     ; only will work with an 320x200 screen w/ screenwidth of 80 bytes
  714. MACRO @ResetLinear
  715.     mov     dx,SC_INDEX
  716.     mov     ax,0E04h
  717.     out     dx,ax               ; enable chain4 mode
  718.  
  719.     mov     dx,CRTC_INDEX       ; reprogram the CRT Controller
  720.     mov     ax,04014h           ; turn on dword mode
  721.     out     dx,ax
  722.     mov     ax,0a317h           ; turn off byte mode
  723.     out     dx,ax
  724. ENDM
  725.